Instantiate body instead of using ParamTypeMapper#13
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements body substitution for generic functions to enable proper trait resolution. Instead of using a ParamTypeMapper to translate type parameters symbolically, the PR substitutes the MIR body with concrete generic arguments (e.g., i32), allowing trait method resolution to work correctly when analyzing generic functions with trait bounds.
Key Changes:
- Replace the
ParamTypeMapperapproach with direct MIR body substitution usingEarlyBinder::instantiate - Update
def_ty_with_argsto work withmir_ty::GenericArgsRefinstead ofrty::TypeArgs - Add
placeholder_generic_argsmethod to generate placeholder arguments for generic functions during analysis
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/rty.rs | Remove Hash and PartialEq derives from types that don't need them; remove TypeArgs from public API |
| src/refine/template.rs | Remove ParamTypeMapper trait and related machinery; simplify translate_param_type |
| src/chc.rs | Remove Hash and PartialEq derives from CHC types |
| src/analyze.rs | Update caching to use GenericArgsRef; add local_fn_sig_with_body helper method |
| src/analyze/crate_.rs | Replace type_builder with generic_args approach; add placeholder_generic_args method |
| src/analyze/local_def.rs | Update to use local_fn_sig_with_body; add generic_args method for body substitution |
| src/analyze/basic_block.rs | Simplify function call type resolution to pass GenericArgsRef directly |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
coeff-aij
pushed a commit
to coeff-aij/thrust
that referenced
this pull request
Jan 12, 2026
Instantiate body instead of using ParamTypeMapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
follow-up of #8 for #10
Translating
ParamTyin TypeBuilder (viaParamTypeMapper) is insufficient for resolving traits in #10 because the actualGenericArgsare unknown when typing function calls.In the call to
genericwithin the following example, def_ty_with_args attempts to checkgenericusing int as a type argument (note: this is not i32, as it is already converted to rty::Type). However, BasicBlockAnalyzer unable to find the DefId of<i32 as Trait>::tbecause it only knows that T=int, but does not know T=i32, making it impossible to use Instance::resolve with fully substituted type arguments (i32 here).